home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / bindings / fun / listbuff < prev    next >
Encoding:
Text File  |  1996-09-27  |  5.4 KB  |  186 lines

  1. @if-using not(ocl-file-listbuff)
  2.    @use (ocl-file-listbuff)
  3.    @if-using not(ocl-file-hide-buffer) @lib hide-buffer @fi
  4.    @if-using not(ocl-file-buff-size)   @lib buff-size   @fi
  5.    ;OCL{{{}}}
  6.    ;OCL{{{  reference description
  7.    @if-using ( FUN-REFERENCE ) ; 1 ;
  8.    Provides a function, which opens a screen size  window  containing  all
  9.    active buffers. A menu appears for selecting one of the buffers.
  10.    @fi
  11.    ;OCL}}}
  12.    ;OCL{{{  variables
  13.    ( defvar ( l-b-old-no l-b-ind l-b-i l-b-dummy ) )
  14.    ;OCL}}}
  15.    ;OCL{{{  history
  16.    ( history l-b-menu )
  17.    ;OCL}}}
  18.    ;OCL{{{  list-buffers
  19.    ;OCL{{{  reference
  20.    @if-using ( FUN-REFERENCE ) ; 2 ; list-buffers-called
  21.    ;OCL{{{  @list-buff-ref list-buffers
  22.    Open a screen-sized window and list all buffers. Each line contains:
  23.  
  24.    @ref-start-item buffernumber [D] [*] filename
  25.    * marks a changed file
  26.    D marks a directory or the list of edited files
  27.    @ref-end-item
  28.  
  29.    A menu appears, for selecting the buffer,  you  want  to  edit  now.
  30.    newline-and-indent will return  to  the  old buffer. There are items
  31.    up/down in the menu, to scroll the buffer list.
  32.  
  33.    begin-prompt-macro and end-prompt-macro are used, to use the correct
  34.    keytables/modes.
  35.    ;OCL}}}
  36.    @fi
  37.    ;OCL}}}
  38.    ( deffun list-buffers
  39.       ( set l-b-old-no current-buffer-number
  40.         set l-b-ind used-buffers
  41.         open-hidden-dummy-buffer(false)
  42.         set l-b-dummy current-buffer-number
  43.         set l-b-i used-buffers
  44.         ;OCL{{{  get all buffers
  45.         do
  46.          ( if <>(l-b-i current-buffer-number)
  47.             ;OCL{{{  add entry to list
  48.             ( goto-buffer-number l-b-i
  49.               ;OCL{{{  get buffer-no,change and filename
  50.               history-edit-filename l-b-menu ()
  51.               beginning-of-line
  52.               "  ;
  53.               "  ;
  54.               "  ;
  55.               counter l-b-ind
  56.               "  ;
  57.               "  ;
  58.               "  ;
  59.               if test-file-changed ( "* ) else ( "  ) fi
  60.               if =(file-type 0) ( "  ) else ( "D ) fi
  61.               "  ;
  62.               "  ;
  63.               "  ;
  64.               newline-and-indent
  65.               ;OCL}}}
  66.               goto-buffer-number l-b-dummy
  67.               ;OCL{{{  add to buffer
  68.               goto-line-counter 1
  69.               newline-and-indent
  70.               previous-line
  71.               get-history l-b-menu 0
  72.               ;OCL}}}
  73.               set l-b-ind -(l-b-ind 1)
  74.             )
  75.             ;OCL}}}
  76.            fi
  77.            set l-b-i -(l-b-i 1)
  78.          )
  79.         while l-b-i
  80.         ;OCL}}}
  81.         set-file-unchanged
  82.         ;OCL{{{  gen menu string
  83.         history-edit l-b-menu ()
  84.         "down
  85.         set l-b-i -(used-buffers 1)
  86.         do
  87.          ( beginning-of-line
  88.            counter l-b-i
  89.            "  ;
  90.            set l-b-i -(l-b-i 1)
  91.          )
  92.         while l-b-i
  93.         beginning-of-line
  94.         "up "  ;
  95.         newline-and-indent
  96.         ;OCL}}}
  97.         ;OCL{{{  show list
  98.         beginning-of-fold
  99.         end-of-line
  100.         newline-and-indent
  101.         end-of-fold
  102.         beginning-of-line
  103.         newline-and-indent
  104.         full-size-buffer
  105.         set-file-unchanged
  106.         change-buffername "active-buffers newline-and-indent
  107.         screen-on
  108.         redraw-display
  109.         ;OCL}}}
  110.         ;OCL{{{  prompt for new buffer
  111.         local
  112.          ()
  113.          ( set l-b-i l-b-old-no
  114.            do
  115.             (
  116.               ;OCL{{{  prompt for target, active is old buffer
  117.               set l-b-old-no l-b-i
  118.               begin-prompt-macro
  119.               menu-counter l-b-old-no ( history l-b-menu )
  120.               end-prompt-macro
  121.               ;OCL}}}
  122.               case
  123.                ;OCL{{{  show next page
  124.                ( =(l-b-old-no 0) ( previous-page ) )
  125.                ;OCL}}}
  126.                ;OCL{{{  show previous page
  127.                ( >=(l-b-old-no used-buffers) ( next-page ) )
  128.                ;OCL}}}
  129.               default
  130.                ;OCL{{{  break from loop, new target found
  131.                ( if >=(l-b-old-no current-buffer-number)
  132.                   ( set l-b-old-no +(l-b-old-no 1) )
  133.                  fi
  134.                  return-from-macro
  135.                )
  136.                ;OCL}}}
  137.               esac
  138.             )
  139.            while true
  140.          )
  141.         ;OCL}}}
  142.         ;OCL{{{  return to wished buffer
  143.         screen-off
  144.         goto-buffer-number l-b-old-no
  145.         set l-b-old-no current-buffer-id
  146.         goto-buffer-number l-b-dummy
  147.         leave-hidden-dummy-buffer(l-b-old-no)
  148.         set l-b-dummy 0
  149.         ;OCL}}}
  150.       )
  151.    )
  152.    ;OCL}}}
  153.    ;OCL{{{  abort-hook-add
  154.    @if-using not(ABORT-HOOK-ADD)
  155.       @use (ABORT-HOOK-ADD)
  156.       ( defmac abort-hook-add ( ) )
  157.    @fi
  158.    ( defmac abort-hook-add-saved ( abort-hook-add ) )
  159.    ( undeclare ( abort-hook-add ) )
  160.    ( defmac abort-hook-add
  161.       ( abort-hook-add-saved
  162.         if l-b-dummy
  163.          ( set l-b-dummy 0
  164.            goto-buffer-number l-b-dummy
  165.            set-file-unchanged
  166.            exit-buffer
  167.            restore-buffer-layout
  168.            goto-buffer-number l-b-old-no
  169.          )
  170.         fi
  171.       )
  172.    )
  173.    ( undeclare ( abort-hook-add-saved ) )
  174.    ;OCL}}}
  175.    ;OCL{{{  reference hooks
  176.    @if-using ( FUN-REFERENCE ) ; 3 ;
  177.    The  libary  defines  a  macro   `abort-hook-add'   and   a   OCL   tag
  178.    ABORT-HOOK-ADD. Add  this  to  your abort-macro. In this case, aborting
  179.    the buffer listing will restore the old state!
  180.    @fi
  181.    ;OCL}}}
  182.    ;OCL{{{  undelcares
  183.    ( undeclare ( l-b-old-no l-b-ind l-b-i l-b-dummy ) )
  184.    ;OCL}}}
  185. @fi
  186.